import os
import sys

aapt_path = '/Users/lzz/Library/Android/sdk/build-tools/29.0.3'
transInputPath = "trans_9patch/in/"
transOutputPath = "trans_9patch/out/"

'''
压缩 9.png 适配从网络获取
* 需配置aapt 环境变量
* input图片格式为.9.png
'''


def trans29patch():
    print('os.path:')
    print(os.path)
    print('sys.path')
    print(sys.path)

    transInFileList = []
    if os.path.exists(transInputPath):
        transInFileList = os.listdir(transInputPath)
    if len(transInFileList) == 0:
        print("无文件处理")
        return

    if not os.path.exists(transOutputPath):
        os.makedirs(transOutputPath)

    for inputItem in transInFileList:
        if not inputItem.endswith(".9.png"):
            print("不符合.9格式跳过" + outputName)
            continue
        outputName = inputItem.split(".")[0] + "_out.png"
        print("outputName：" + outputName)
        order = os.popen(
            "aapt s -i " + transInputPath + inputItem + " -o " + transOutputPath + outputName).read()
        print("输出：" + order)
